import unittest
# from HtmlTestRunner import HTMLTestRunner
import HTMLTestRunner  #导入主包
import test003

class Test001(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('初始化')
    def test_case001(self):
        print('testcase001')
    def test_case002(self):
        print('testcase002')
    def test_case003(self):
        print('testcase003')
    @classmethod
    def tearDownClass(cls):
        print('资源回收')

class Test002(unittest.TestCase):
    def setUp(self):
        print('初始化')
    def test_case001(self):
        print('testcase001')
    def test_case002(self):
        print('testcase002')
    def test_case003(self):
        print('testcase003')
    def tearDown(self):
        print('资源回收')



if __name__ == '__main__':
    # unittest.main()
    suite = unittest.TestSuite()#实例化一个测试集对象
    # suite.addTests(unittest.TestLoader().loadTestsFromTestCase(Test001)) #加载整个类至测试集中
    suite.addTests(unittest.TestLoader().loadTestsFromModule(test003))  #添加模块至测试集
    # suite.addTests(unittest.TestLoader().loadTestsFromName("test003.Test001.test_case001")) #按照用例名称添加至测试集
    # runner = unittest.TextTestRunner()#实例化一个runner负责执行

    # runner.run(suite)#执行测试集
    # unittest.TextTestRunner().run(suite)
    with open("test.html","w",encoding="utf8") as file:
        runner = HTMLTestRunner.HTMLTestRunner(stream=file,verbosity=1,title="测试报告",description="unittest 简单测试报告")
        runner.run(suite)


